
#include "EquipmentMina.h"
#include "../PlayScenarioPanel.h"

#define EQUIPMENTMINA_DEFAULT_QUANTITY 3
#define EQUIPMENTMINA_MAX_QUANTITY 3

EquipmentMina::EquipmentMina(Widget* parent): Equipment(MINA,parent)  {
	this->quantityLeft = EQUIPMENTMINA_DEFAULT_QUANTITY;
}

EquipmentMina::EquipmentMina(DTOEquipment* dtoEquipment,Widget* parent):
Equipment(dtoEquipment, parent){
	this->quantityLeft = dtoEquipment->value;
}

void EquipmentMina::handleEvent(Event event){
	EventType eventType = event.getType();

	//Translate EventType
	if (eventType == UserEvent) {
		if (event.getEvent()->user.code == UserKeyPressed) {
			eventType = KeyPressed;
		} else if (event.getEvent()->user.code == UserKeyReleased) {
			eventType = KeyReleased;
		}
	}

	if (this->quantityLeft > 0 && event.getKey()== Letter_I && eventType == KeyPressed){
		((PlayScenarioPanel*)parent)->addAmmo(AMMO_MINA);
		this->quantityLeft--;
	}
}

int EquipmentMina::reduceLife(int value,playElement element){
	return value;
}

void EquipmentMina::showOn(SDL_Surface* surface,int offsetX,int offsetY) {
	if(quantityLeft == 0){
		emptyFlag = true;
	}
}

DTOEquipment* EquipmentMina::getDTO() {
	return new DTOEquipment(MINA,this->quantityLeft,((PlayScenarioPanel*)parent)->getOwner());
}

void EquipmentMina::updateStatus(){
	if ( (quantityLeft + EQUIPMENTMINA_DEFAULT_QUANTITY) >
			EQUIPMENTMINA_MAX_QUANTITY)
		quantityLeft = EQUIPMENTMINA_MAX_QUANTITY;
	else
		quantityLeft += quantityLeft + EQUIPMENTMINA_DEFAULT_QUANTITY;
}

EquipmentMina::~EquipmentMina() {
}

